<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import userAccount from '@/api/backend/userAccount.js'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool.js'
import * as common from '@/utils/common.js'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  userAccount.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  userAccount.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'user_account',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'drawer',
    width: 600
  },
  api: userAccount.getList,
  recycleApi: userAccount.getRecycleList,
  add: {
    show: true,
    api: userAccount.save,
    auth: ['account:save']
  },
  edit: {
    show: true,
    api: userAccount.update,
    auth: ['account:update']
  },
  delete: {
    show: true,
    api: userAccount.deletes,
    auth: ['account:delete'],
    realApi: userAccount.realDeletes,
    realAuth: ['account:realDeletes']
  },
  recovery: {
    show: true,
    api: userAccount.recoverys,
    auth: ['account:recovery']
  }
})

const columns = reactive([
  {
    title: "用户ID，主键",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "用户名",
    dataIndex: "username",
    formType: "input",
    search: true
  },
  {
    title: "手机区号",
    dataIndex: "code",
    formType: "input",
    search: true
  },
  {
    title: "手机",
    dataIndex: "phone",
    formType: "input",
    search: true
  },
  {
    title: "用户邮箱",
    dataIndex: "email",
    formType: "input",
    search: true
  },
  {
    title: "密码",
    dataIndex: "password",
    formType: "input"
  },
  {
    title: "状态 ",
    dataIndex: "status",
    formType: "select",
    dict: {
      data: [
        {
          label: "正常",
          value: "1"
        },
        {
          label: "停用",
          value: "2"
        }
      ],
      translation: true
    }
  },
  {
    title: "最后登陆IP",
    dataIndex: "login_ip",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "最后登陆时间",
    dataIndex: "login_time",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  }
])
</script>
<script> export default { name: 'account' } </script>